Skip to content

Fix: guard against null line_model in distance.element position setter#692

Open
xianjianlf2 wants to merge 1 commit into
GoogleChromeLabs:mainfrom
xianjianlf2:fix/distance-element-null-guard
Open

Fix: guard against null line_model in distance.element position setter#692
xianjianlf2 wants to merge 1 commit into
GoogleChromeLabs:mainfrom
xianjianlf2:fix/distance-element-null-guard

Conversation

@xianjianlf2

Copy link
Copy Markdown

Summary

Fixes #686.

The position setter in app/components/selection/distance.element.js passed line_model directly into the styleProps setter and render(), both of which destructure it ({y, x, d, q, v, color} and {q, d} respectively).

When line_model is null or undefined — which can happen during rapid mouse movement or when measured elements dynamically unmount in single-page apps — destructuring throws a TypeError and crashes the measurement overlay.

Change

Add an early-return guard at the top of the position setter so a falsy line_model is ignored instead of crashing:

set position({line_model, node_label_id}) {
  if (!line_model) return

  this.styleProps = line_model
  this.$shadow.innerHTML = this.render(line_model, node_label_id)
}

Minimal, no behavior change for valid input.

The position setter passed line_model straight to the styleProps setter
and render(), both of which destructure it. When line_model is null or
undefined (e.g. during rapid mouse movement or when measured elements
unmount in SPAs), this threw a TypeError. Bail out early when line_model
is falsy.

Fixes GoogleChromeLabs#686
@google-cla

google-cla Bot commented Jun 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Potential TypeError in distance.element.js due to missing null/undefined check on line_model

1 participant